<?php
/**
 * 考勤系统用户
 */
namespace app\attendance\controller;

use app\attendance\Base;
use think\Config;
use think\Db;
use think\Loader;
use think\exception\HttpException;
use baseutils\BaseUtil; # 验证类

use com\gdl\kq\interfaces\AttAdminUserServiceClient;
use com\gdl\kq\dataobject\adminuser\UserDTO; 
use com\gdl\kq\dataobject\adminuser\UserInfoDTO; 
use com\gdl\kq\dataobject\adminuser\UserPositionDTO; 
use com\gdl\kq\dataobject\adminuser\UserEditDTO; 
use com\gdl\kq\dataobject\adminuser\UserEditPhoto; 
use com\gdl\kq\dataobject\adminuser\PositionDTO; 

class AdminUser extends Base
{
	
	//用户列表
	public function getMemberList()
    {
    	$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}

		#其他参数
		$likeName = $this->request->param('name') ? getStr($this->request->param('name')) : ''; 
		$departmentId = $this->request->param('departmentId') ? getStr($this->request->param('departmentId')) : '';
		$positionId =  $this->request->param('positionId') ? getStr($this->request->param('positionId')) : '';
		$groupId =  $this->request->param('groupId') ? getStr($this->request->param('groupId')) : '';
		$type =  $this->request->param('type') ? getStr($this->request->param('type')) : ''; #如果等于all则判断该管理员的所有用户
		$photoStatus = $this->request->param('photoStatus') ? getStr($this->request->param('photoStatus')) : '';#留底照片状态 4: 未上传 1:未审核 2:未通过 3:已审核
		$offset = $this->request->param('offset') ? getStr($this->request->param('offset')) : 1; #分页
		$num = $this->request->param('num') ? getStr($this->request->param('num')) : 10; #条数


		#其他参数
		try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$sdkData = ['likeName'=>$likeName, 'departmentId'=>$departmentId, 'unitId'=>$unitId, 'positionId'=>$positionId,'platformId'=>$platformId,'adminUserId'=>$adminUserId,'type'=>$type,'photoStatus'=>$photoStatus,'groupId'=>$groupId];
			$userDO->data = $sdkData;
			$userDO->offset = $offset; 
			$userDO->num = $num; 
			$result = $api->getMemberList($userDO);
			if($result->success == true){
				$msg['msg'] = $result->message;
				$msg['code'] = $result->code;
				$msg['data'] = $result->data;
				$msg['counts'] = $result->counts;
				if(empty($result->data)){
					$msg['msg'] = "暂无数据";
				}	 
			}

		} catch (Exception $ex) {
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);	 
	}

	//添加人员
	public function addUser(){
		$msg = ['msg'=>'添加失败','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : 0; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}

		#其他参数 
		$name = $this->request->param('name') ? getStr($this->request->param('name')) : '';
		$idcard = $this->request->param('idcard') ? getStr($this->request->param('idcard')) : '';
		$password =$this->request->param('password') ? getStr($this->request->param('password')) : '';
		$phone = $this->request->param('phone') ? getStr($this->request->param('phone')) : '';
		$workNumber = $this->request->param('workNumber') ? getStr($this->request->param('workNumber')) : '';
		$departmentId = $this->request->param('departmentId') ? getStr($this->request->param('departmentId')) : '';
		$positionId = $this->request->param('positionId') ? getStr($this->request->param('positionId')) : '';
		$isLeader = $this->request->param('isLeader') ? getStr($this->request->param('isLeader')) : 2; # 2：普通员工 1：领导
		$status = $this->request->param('status') ? getStr($this->request->param('status')) : 2; # 2：正常 1：删除
		$photo = $this->request->param('photo') ? getStr($this->request->param('photo')) : ''; #图片链接

		#处理部门 前端传过来的可能是一个1 也可能是一个逗号分隔
		$departArray = explode(",",$departmentId);
		$departmentId =  end($departArray);

		#验证
		$util = new BaseUtil();
		if (!empty($idcard)) {
			if(!$util->isIdCard($idcard)){
				$msg['msg'] = "请输入正确的身份证";
            	return json_encode($msg);	
			}
            
        }
        if (!empty($phone)) {
        	if(!$util->IsMobile($phone)){
        		$msg['msg'] = "请输入正确的手机号码";
            	return json_encode($msg);	
        	}
            
        }
        if(empty($name)){ $msg['msg'] = "请输入姓名"; return json_encode($msg);}
        if(empty($password) || strlen($password)<6){ $msg['msg'] = "请输入六位密码"; return json_encode($msg);} 
        if(empty($departmentId)){ $msg['msg'] = "请选择部门"; return json_encode($msg);}
        if(empty($positionId)){ $msg['msg'] = "请选择职位"; return json_encode($msg);}
        if(empty($workNumber)){$msg['msg'] = "请添加工号"; return json_encode($msg);}

		$username = \CUtf8PY::encode($name,'all'); # 拼音账号

		#数据集
		$sdkData = [
			'userName'=>$username.mt_rand(10000,99999),
			'realName'=>$name,
			'idcard'=>$idcard,
			'phone'=>$phone,
			'jobNumber'=>$workNumber,
			'password'=>$password,
			'photoStatus'=>4,  #4: 未上传 1:未审核 2:未通过 3:已审核'
			'departmentId'=>$departmentId,
			'positionId'=>$positionId,
			'photo'=>$photo,
			'status'=>$status,
			'createTime'=>time(),
			'isCharge'=>$isLeader,
			'status'=>$status,
			'isBind'=>2, #2:未绑定 1：绑定
			'isFirstLogin'=>1, # 1：第一次登录 2：正常
			'platformId'=>$platformId,
			'unitId'=>$departmentId?$departmentId:$unitId, #如果他没有部门id 那就拿部门id做unitid	
		];
		if($photo){$sdkData['photo'] = $photo; $sdkData['photoStatus'] = 3;}
		if($phone){$sdkData['isBind'] = 1;} #是否绑定手机 

		try {
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserEditDTO();

			# 数据集
			$userDO->data = $sdkData; 
			$result = $api->addUser($userDO);
			if($result->success ==true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				$msg['data'] = [];
			}
		} catch (Exception $ex) {
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);	
	}
	//编辑用户 
	public function editMemberInfo(){

		$msg = ['msg'=>'编辑失败','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : 0; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}

		#其他参数 
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : '';
		$groupId = $this->request->param('groupId') ? getStr($this->request->param('groupId')) : '0';
		$name = $this->request->param('name') ? getStr($this->request->param('name')) : '';
		$idcard = $this->request->param('idcard') ? getStr($this->request->param('idcard')) : '';
		$password =$this->request->param('password') ? getStr($this->request->param('password')) : '';
		$phone = $this->request->param('phone') ? getStr($this->request->param('phone')) : '';
		$workNumber = $this->request->param('workNumber') ? getStr($this->request->param('workNumber')) : '';
		$departmentId = $this->request->param('departmentId') ? getStr($this->request->param('departmentId')) : '';
		$positionId = $this->request->param('positionId') ? getStr($this->request->param('positionId')) : '';
		$isLeader = $this->request->param('isLeader') ? getStr($this->request->param('isLeader')) : 2; # 2：普通员工 1：领导
		$status = $this->request->param('status') ? getStr($this->request->param('status')) : 2; # 2：正常 1：删除
		$photo = $this->request->param('photo') ? getStr($this->request->param('photo')) : ''; #图片链接
		#处理部门
		$departArray = explode(",",$departmentId);
		$departmentId =  end($departArray);

		#验证
		if(empty($userId)){$msg['msg'] = "请选择用户"; return json_encode($msg);}
		$util = new BaseUtil();
		#验证
		$util = new BaseUtil();
		if (!empty($idcard)) {
			if(!$util->isIdCard($idcard)){
				$msg['msg'] = "请输入正确的身份证";
            	return json_encode($msg);	
			}
            
        }
        if (!empty($phone)) {
        	if(!$util->IsMobile($phone)){
        		$msg['msg'] = "请输入正确的手机号码";
            	return json_encode($msg);	
        	}
            
        }
        if(empty($name)){ $msg['msg'] = "请输入姓名"; return json_encode($msg);}
        if(empty($password) || strlen($password)<6){ $msg['msg'] = "请输入六位密码"; return json_encode($msg);} 
        //if(empty($departmentId)){ $msg['msg'] = "请选择部门"; return json_encode($msg);}
        if(empty($positionId)){ $msg['msg'] = "请选择职位"; return json_encode($msg);}
        if(empty($workNumber)){$msg['msg'] = "请添加工号"; return json_encode($msg);}

		$username = \CUtf8PY::encode($name,'all'); # 拼音账号

		#数据集
		$sdkData = [
			'userName'=>$username.mt_rand(10000,99999),
			'realName'=>$name,
			'idcard'=>$idcard,
			'phone'=>$phone,
			'jobNumber'=>$workNumber,
			'password'=>$password,
			'departmentId'=>$departmentId,
			'unitId'=>$departmentId,
			'positionId'=>$positionId,
			'status'=>$status,
			'createTime'=>time(),
			'isCharge'=>$isLeader,
			'status'=>$status,
			'isBind'=>2, #2:未绑定 1：绑定	
		];
		if($photo){$sdkData['photo'] = $photo; $sdkData['photoStatus'] = 3;}
		if($phone){$sdkData['isBind'] = 1;} #是否绑定手机 

		//'photoStatus'=>4,  #4: 未上传 1:未审核 2:未通过 3:已审核'
		//'isFirstLogin'=>1, # 1：第一次登录 2：正常
		//'platformId'=>$platformId,
		//'unitId'=>$departmentId?$departmentId:$unitId, #如果他没有部门id 那就拿部门id做unitid
		try {
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserEditDTO();

			# 数据集
			$userDO->userId = $userId;
			$userDO->agId = $groupId;
			$userDO->data = $sdkData; 
			$result = $api->editMemberInfo($userDO);
			if($result->success ==true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				$msg['data'] = [];
			}
		} catch (Exception $ex) {
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);	
	}

	//用户详情 包含留底 取相关相关字段
	public function userInfo(){
		$msg = ['msg'=>'未找到相关用户','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}
		
		#其他参数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : '';

		# 验证
		if(empty($userId)){$msg['msg'] = "请选择用户"; return json_encode($msg);}

		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserEditDTO();

			# 数据集
			$userDO->userId = $userId; 
			$result = $api->userInfo($userDO);
			if($result->success ==true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				if(!empty($result->data)){
					$msg['data'] = $result->data[0];
				}
			}
		}catch(Exception $e){
			$msg['msg'] = $e->getMessage();
		}

		return json_encode($msg);
	}

	//审核照片
	public function verifyMemberPhoto(){
		$msg = ['msg'=>'暂未审核','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : 0; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : 0; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		
		#其他参数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : '';
		$status = $this->request->param('status') ? getStr($this->request->param('status')) : '';
		$text = $this->request->param('photoInfo') ? getStr($this->request->param('photoInfo')) : '';
		$photo = $this->request->param('photo') ? getStr($this->request->param('photo')) : ''; #图片链接

		#验证
		if(empty($userId)){$msg['msg'] = "请选择需要审核的用户"; return json_encode($msg);}

		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserEditPhoto();

			$sdkData = ['photo'=>$photo];
			$userDO->userId = $userId;
			$userDO->status = $status;
			$userDO->text = $text;
			$userDO->data = $sdkData;
			$result = $api->verifyMemberPhoto($userDO);

			if($result->success ==true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message; 
				$msg['data'] = $result->data; 
			}
		}catch(Exception $e){
			$msg['msg'] = $e->getMessage();
		}

		return json_encode($msg);
	}

	//删除用户 单个删除 批量删除
	public function deleteOneMember(){
		$msg = ['msg'=>'删除失败','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : 0; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : 0; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}
		
		#其他参数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : ''; #多个用逗号分隔

		#处理去除，，，
		$myUserId = explode(",", $userId);
		$userArray = [];
		foreach($myUserId as $v){
			if(!empty($v)){
				$userArray[] = $v;
			}
		}
		$userId = implode(",", $userArray);

		#验证
		if(empty($userId)){$msg['msg'] = "请选择用户"; json_encode($msg);}

		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserInfoDTO();
			$userDO->idstr = $userId;
			$result = $api->deleteOneMember($userDO);

			if($result->success ==true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message; 
				$msg['data'] = $result->data; 
			}
		}catch(Exception $e){
			$msg['msg'] = $e->getMessage();
		}

		return json_encode($msg);
	}

	//人员列表组织架构图
	public function getMemberUnitsList(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}
		// 模糊查询部门名称
		$likeName = $this->request->param('likeName') ? getStr($this->request->param('likeName')) : ""; #模糊查询部门名称

		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$sdkData = ['likeName'=>$likeName,'adminUserId'=>$adminUserId];
			$userDO->platformId = $platformId;
			$userDO->unitId = $unitId;
			$userDO->data = $sdkData;
			$result = $api->getMemberUnitsList($userDO);
			if($result->success == true){
				$msg['msg'] = $result->message;
				$msg['code'] = $result->code;
				if(!empty($result->data)){
					$msg['data'] = json_decode($result->data[0][0]);
				}
			}

		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);
	}

	//部门列表
	public function getDepartmentList(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		// if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}

		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$sdkData = ['adminUserId'=>$adminUserId];
			$userDO->platformId = $platformId;
			$userDO->unitId = $unitId;
			$userDO->data = $sdkData;
			$result = $api->getDepartmentList($userDO);
			if($result->success == true){
				$msg['msg'] = $result->message;
				$msg['code'] = $result->code;
				if(!empty($result->data)){
					$msg['data'] = json_decode($result->data[0][0]);
				}
			}

		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);
	}
	//单个单位下属部门 单个部门下属分组
	public function getDepartmentChildList(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}
		if(empty($unitId)){ $msg['msg'] = "请选择单位"; return json_encode($msg);}
		
		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$userDO->platformId = $platformId;
			$userDO->unitId = $unitId;

			$result = $api->getDepartmentChildList($userDO); 
			if($result->success == true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				if(!empty($result->data)){
					$msg['data'] = json_decode($result->data[0]['list']);
				}
			}
		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}

		return json_encode($msg);
	}

	// 下载用户execl
	public function downExeclUser(){
		ob_end_clean(); # 清空缓冲区
		$msg = ['msg'=>'没有可导出的数据','code'=>'400','data'=>[]];
		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : ""; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : ""; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);}

		#其他参数
		$likeName = $this->request->param('name') ? getStr($this->request->param('name')) : ''; 
		$departmentId = $this->request->param('departmentId') ? getStr($this->request->param('departmentId')) : '';
		$positionId =  $this->request->param('positionId') ? getStr($this->request->param('positionId')) : '';
		$groupId =  $this->request->param('groupId') ? getStr($this->request->param('groupId')) : '';
		$type =  $this->request->param('type') ? getStr($this->request->param('type')) : '';
		$offset = $this->request->param('offset') ? getStr($this->request->param('offset')) : 1; #分页
		$num = $this->request->param('num') ? getStr($this->request->param('num')) : 100000; #条数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : ''; #条数 多个逗号分隔
		$photoStatus = $this->request->param('photoStatus') ? getStr($this->request->param('photoStatus')) : '';#留底照片状态 4: 未上传 1:未审核 2:未通过 
		if(!empty($userId)){
			$userArray = explode(",",$userId);
			$userId = [];
			foreach ($userArray as $key) {
				if(!empty($key)){
					$userId[] = $key;
				}
			}
			$userId = implode(",", $userId);
		}

		#其他参数
		try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$sdkData = ['likeName'=>$likeName, 'departmentId'=>$departmentId, 'unitId'=>$unitId, 'positionId'=>$positionId,'platformId'=>$platformId,'userId'=>$userId,'adminUserId'=>$adminUserId,'type'=>$type,'photoStatus'=>$photoStatus,'groupId'=>$groupId];
			$userDO->data = $sdkData;

			$userDO->offset = $offset; 
			$userDO->num = $num; 
			$result = $api->getMemberList($userDO);
			
			if($result->success == true){
				if(empty($result->data)){$msg['msg'] = "没有可导出的数据"; return json_encode($msg);}
				$header = ['USERID','姓名','工号','部门/公司','职位','身份证','手机号','留底照片'];
                $list = [];
                foreach($result->data as $key=>$v){ 
                    $list[]= [
                        $v['id'],
                        $v['realName'],
                        "|--".$v['jobNumber'],
                        $v['departmentName'],
                        $v['positionName'],
                        "|--".$v['idcard'],
                        "|--".$v['phone'],
                        $this->getVface($v['photoStatus']), 
                    ];
                } 
                $version = '2007';
                $width = array('C'=>30,'D'=>30,'E'=>30);
                \Excel::oneExport($header, $list, "成员列表", $version,$width);
			}

		} catch (Exception $ex) {
			$msg['msg'] = $ex->getMessage();
		}
		return json_encode($msg);	
	}
	// 获取考勤分组列表
	public function getGroupList(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : "0"; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : "0"; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);} 
		
		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserDTO();
			$sdkData = ['adminUserId'=>$adminUserId];
			$userDO->platformId = $platformId;
			$userDO->unitId = $unitId;
			$userDO->data = $sdkData;

			$result = $api->getGroupList($userDO); 
			if($result->success == true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				$msg['data'] = $result->data;
			}
		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}

		return json_encode($msg);
	}
	//调整部门人员
	public function changeMemberPosition(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : "0"; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : "0"; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);} 

		#其他参数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : ""; #用户id 多个用逗号分隔
		$departmentId = $this->request->param('departmentId') ? getStr($this->request->param('departmentId')) : ""; #部门id
		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserEditDTO();
			$userDO->userId = $userId;
			$userDO->agId = $departmentId;

			$result = $api->changeMemberPosition($userDO); 
			if($result->success == true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				$msg['data'] = $result->data;
			}
		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}

		return json_encode($msg);
	}

	//调整用户职位
	public function editMemberListByPositionId(){
		$msg = ['msg'=>'暂无数据','code'=>'400','data'=>[]];

		# 公共参数
		$adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
		$adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
		$platformId = $this->request->param('platformId') ? getStr($this->request->param('platformId')) : "0"; #平台id
		$unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : "0"; #单位id
		if(empty($platformId)){ $msg['msg'] = "请选择平台"; return json_encode($msg);} 

		#其他参数
		$userId = $this->request->param('userId') ? getStr($this->request->param('userId')) : ""; #用户id 多个用逗号分隔
		$positionId = $this->request->param('positionId') ? getStr($this->request->param('positionId')) : ""; #职位id
		try{
			# 实例化
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
			$api = new AttAdminUserServiceClient(NULL);
			\ApiClient::build($api); 
			$userDO = new UserPositionDTO();
			$userDO->positionid = $positionId;
			$userDO->update = $userId;

			$result = $api->editMemberListByPositionId($userDO); 
			if($result->success == true){
				$msg['code'] = $result->code;
				$msg['msg'] = $result->message;
				$msg['data'] = $result->data;
			}
		}catch(Exception $ex){
			$msg['msg'] = $ex->getMessage();
		}

		return json_encode($msg);
	}

	 # 留底照片状态
    private function getVface($face=4){
        $faces = "未上传";
        if($face==4){
            $faces = "未上传";
        }
        if($face==1){
            $faces = "审核失败";   
        }
        if($face==2){
            $faces = "审核通过";
        }
        if($face==3){
            $faces = "审核中";
        }
        return $faces;
    }
	 
}
